package cool.tianyou.blue.bird;

import java.util.ArrayList;
import java.util.List;

import lombok.Data;

/**
 * @author Liutianyou
 * @date 2022/10/15 15:16
 */
public class Classifier {
    
    static final List<Rule> rules = new ArrayList<>();
    
    
    static {
        rules.add(new Rule(1, ".*?(验证码|校验码|交易码).*", "验证码","验证码"));
        rules.add(new Rule(1,
            "^温馨提示：您于\\d+日\\d+时\\d+分交费\\d+元，账户当前可用余额为\\d+\\.\\d+元。点击进入 .*? 查询详情。【中国联通】$", "缴费到账","通知"));
        rules.add(new Rule(1,
            "^温馨提示：您办理的.*?，每月1-3日将全额扣除当月套餐基本费用，请您近期预存足够的话费，避免费用不足停机，影响您的正常通信。您可微信关注“.*?”公众号查询实时话费、余额或更多详情。\\(.*\\)$",
            "扣费提醒","通知"));
        rules.add(new Rule(1, "^尊敬的客户，您于\\d+年\\d+月\\d+日\\d+时\\d+分成功充值\\d+.\\d+元。查询账户余额，您可微信关注.*$",
            "缴费到账","通知"));
        rules.add(new Rule(1,
            "【流量.*?】截至.*?，您当月套餐内(?:的)*国内通用流量已.*【.*?】",
            "流量提醒","通知"));
        rules.add(new Rule(1, "^【丰巢】请凭取件码『\\d+』至.*?取.*?的包裹.*", "取件提醒","快递"));
        rules.add(new Rule(1, "^【丰巢】凭取件码\\d+至.*", "取件提醒","快递"));
        rules.add(
            new Rule(1, "你定投.*?\\d+.\\d+元已扣款成功，购买结果将于\\d+年\\d+月\\d+日确认。退订请回VM【蚂蚁基金】", "基金定投扣款","通知"));
        rules.add(new Rule(1, "您尾号\\d+的信用卡\\d+日\\d+:\\d+消费.*\\d+.\\d+元。\\[招商银行\\]", "信用卡消费提醒","通知"));
        rules.add(new Rule(1,
            "【京东金融】您本期白条账单待还\\d+.\\d+元，最后还款日\\d+月\\d+日。回复FQ将\\d+\\.\\d+元分\\d+期还。分期成功后本期仅需还\\d+\\.\\d+元。",
            "白条还款","提醒"));
        rules.add(new Rule(1, "【快递超市】您好，您的.*?\\d+已到.*?，凭.*?来取，联系电话\\d+", "取件提醒","提醒"));
        rules.add(
            new Rule(1, "您尾号\\d+的信用卡\\d+日\\d+:\\d+消费人民币\\d+\\.\\d+元。.*?\\[招商银行\\]", "信用卡消费","通知"));
        rules.add(new Rule(1, "【阿里云】尊敬的.*?：.*阿里云云安全中心检测到您存在\\d+个漏洞：.*?.*",
            "阿里云安全提醒","提醒"));
        rules.add(new Rule(1, "【阿里云】您好，您帐号.*?下的.*? 域名.*?.*", "域名提醒","提醒"));
        rules.add(
            new Rule(1, "【.*?】您尾号\\d+的(招行)*信用卡(?:\\d+月)*\\d+日\\d+:\\d+消费(?:人民币|美元)*\\d+\\.\\d+.*?",
                "信用卡消费","通知"));
        rules.add(new Rule(1, "【京东快递】您的快递已到.*?\\.请.*?前来取。地址:.*?电话：\\d+", "取件提醒","快递"));
        rules.add(new Rule(1, "【流量提醒】截止\\d+月\\d+日\\d+时\\d+分，您的.*?通用流量已使用完毕。.*?", "流量提醒","通知"));
        rules.add(new Rule(1, "【阿里云】尊敬的.*?：\\\\n 阿里云云安全中心检测到您存在\\d+个待处理漏洞，.*", "阿里云安全","提醒"));
        rules.add(
            new Rule(1, ".*\\d+\\.\\d+元定投扣款失败，你可尝试手动购买，如扣款渠道余额不足可于15点后更改扣款渠道。【蚂蚁基金】", "基金定投失败","通知"));
        rules.add(new Rule(1, "退款已受理，原订单号.*?，退款流水号.*?，金额\\d+\\.\\d+【支付宝】", "退款受理","通知"));
        rules.add(new Rule(1, ".*送您.*\\d+(\\.\\d+)*元[代金券|红包|优惠券|话费券].*", "营销短信","广告"));
        rules.add(new Rule(1, ".*送您.*\\d+(\\.\\d+)*元[代金券|红包|优惠券|话费券].*", "营销短信","广告"));
        rules.add(new Rule(1, ".*?(赠|获)*.*价值\\d+元.*?(秒杀|给您)*.*", "营销短信","广告"));
        rules.add(new Rule(1, ".*?(返|领)\\d+(\\.\\d+)*元红包.*?", "营销短信","广告"));
        rules.add(new Rule(1, ".*?\\d+(.\\d+)*折.*", "营销短信","广告"));
        rules.add(new Rule(1, "您支付宝.*?花呗\\d{2}月账单\\d+\\.\\d+元，\\d+月\\d+日自动还款.*", "花呗账单","账单"));
        rules.add(new Rule(1, ".*?\\d+(.\\d+)*元.*?券.*?(过期|失效|到账).*?", "营销短信","广告"));
        rules.add(new Rule(1, "^【*公益短信】*.*", "公益短信","提醒"));
        rules.add(new Rule(1, ".*?满\\d+减\\d+.*", "营销短信","广告"));
        rules.add(new Rule(1, "【美团】外卖已.*格口，点击 .*?或使用\\d+取件。", "外卖取餐","提醒"));
        
        rules.add(new Rule(1, "【美团】您的外卖已放在.*?\\d+格口，点击 .*? 或使用\\d+取件", "外卖取餐","提醒"));
        rules.add(new Rule(1, "【账单提醒】尊敬的\\d+用户，您\\d+年\\d+月份账单合计\\d+元，.*?【中国联通】", "通信账单","账单"));
        rules.add(new Rule(1, "【阿里云】尊敬的.*?：云盾云安全中心检测到您的服务器.*", "阿里云安全","提醒"));
        rules.add(new Rule(1, "账户.*?于\\d+月\\d+日\\d+时\\d+分在.*?免密支付\\d+\\.\\d+元，可在支付宝账单查看详情.*?【支付宝】",
            "免密支付","通知"));
        rules.add(new Rule(1, ".*(免费领取|现金红包).*", "营销短信","广告"));
        rules.add(new Rule(1, ".\\d+(\\.\\d+)*元红包.*", "营销短信","广告"));
        rules.add(new Rule(1, ".*(戴口罩|防疫|核酸筛查|疫情防控|疫情).*", "防疫提醒","提醒"));
        rules.add(new Rule(1, "账户.*?于\\d+月\\d+日\\d+时\\d{2}分成功付款\\d+.\\d{2}元【支付宝】", "支付宝付款","通知"));
        rules.add(new Rule(1, "账户.*?在.*?发生消费时商户可自动从你账户扣款，无需确认【支付宝】", "免密支付开通","通知"));
        rules.add(new Rule(1,
            "【北京移动】尊敬的客户，您的(\\d+年)*\\d+月.*?账单已送达，点击查看账单详情 .*?回Q关闭通知。APP查账单更方便.*?【中国移动 139邮箱】",
            "通信账单","账单"));
        rules.add(new Rule(1,
            "您尾号\\d+的银行卡\\d{4}年\\d+月\\d+日  \\d{2}:\\d{2}:\\d{2}与.*?成功签约借记卡快捷支付服务，如非本人操作，请联系95566【中国银行】",
            "银行卡","通知"));
        rules.add(
            new Rule(1, "您好，您的尾号为\\d+招行信用卡，于\\d+日，\\d+:\\d+发生退货，金额\\d+\\.\\d+人民币，退货成功。\\[招商银行\\]",
                "退款","通知"));
        rules.add(new Rule(1, ".{0,6}(市防汛办|市应急办).*", "气象提醒","提醒"));
        rules.add(new Rule(1, "【流量提醒】尊敬的用户，截至\\d+月\\d+日\\d+时，您当月套餐内国内通用流量已用.*?(MB|GB|TB)；.*【中国联通】",
            "流量提醒","通知"));
        rules.add(new Rule(1, "尊敬的客户（户号：.*?，地址：.*?）您好，您已通过.*?成功购电.*?元。.*", "购电","通知"));
        rules.add(
            new Rule(1, "尊敬的客户（户号：.*?，地址：.*?）您好，您购电.*?元，现已成功发送至电表中，当前电表剩余金额为.*?元。.*\\[国网.*电力公司\\]。",
                "购电到账","通知"));
        rules.add(new Rule(1, "【美团】您的外卖已放在.*?格口，点击.*?取餐", "外卖取件","提醒"));
        rules.add(new Rule(1, "温馨提示：您已成功进行积分兑换，扣减积分\\d+分，当前可用积分\\d+分，.*中国联通】", "积分兑换","通知"));
        rules.add(new Rule(1, ".*(反诈).*", "反炸提醒","提醒"));
        rules.add(new Rule(1, "你持有的.*?已进行现金分红，红利\\d+.\\d+元将发放至你的余额宝账户。【蚂蚁基金】", "基金分红","通知"));
        rules.add(new Rule(1, ".*券.*?到账.*", "营销短信","广告"));
        rules.add(new Rule(1,
            "你申请卖.*\\d+\\.\\d+份，确认\\d+\\.\\d+份，手续费\\d+\\.\\d+元，\\d+\\.\\d+元已发放至余额宝账户。退订请回ar【蚂蚁基金】",
            "基金卖出","通知"));
        rules.add(new Rule(1, "买\\d+件\\d+\\.\\d+元", "基金卖出","通知"));
        rules.add(new Rule(1,
            ".*?(双12|(?!<\\d)(?<!\\d)618(?!\\d)|(?<!\\d)99(?!(元积分))|享|55倒计时|双11|大促|宠粉|礼遇季|前\\d小时).*?\\w+(\\.\\w+)+/.*?",
            "广告","广告"));
        rules.add(
            new Rule(1, "你购买的.*?，本期\\d+月\\d+日交费，.*?将通过支付宝自动扣取本期费用\\d+\\.\\d+元。【蚂蚁保】", "保险扣费","通知"));
        rules.add(new Rule(1, "【菜鸟驿站】您的.*?已到.*?，请.*?前凭.*?(及时)*取件.*", "快递取件","快递"));
        rules.add(new Rule(1, "【菜鸟驿站】您的.*?已到.*?，请.*?前凭.*?及时取件.*", "快递取件","快递"));
        
        rules.add(new Rule(1, "【.*?】请凭.*?到.*?领取运单尾号.*?包裹.*", "快递取件","快递"));
        rules.add(new Rule(1, "【阿里云】尊敬的.*?：您的服务器.*?存在异常登录行为.*", "阿里云安全","提醒"));
        rules.add(new Rule(1, "【闲鱼】你有一条用户私聊未回复，点击.*立即回复TA", "闲鱼消息","提醒"));
        rules.add(new Rule(1, "【话费账单】尊敬的.*?客户，您.*?共消费.*?元.*", "账单提醒","账单"));
        rules.add(new Rule(1, "【腾讯王卡】.*已为您的.*?发放\\d+个月(（\\d+天）)*.*?.*", "到账","通知"));
        rules.add(new Rule(1, "【美团外卖】您的退款已成功受理，\\d+\\.\\d+元将退还至.*?，预计\\d+年\\d+月\\d+日前到账。", "退款","通知"));
        rules.add(new Rule(1, "【.*?】遇忙未接.*?主叫:\\d+.*归属:.*时间.*", "漏话提醒","提醒"));
        rules.add(new Rule(1, "【.*?】您账户\\d+于\\d+月\\d+日\\d+:\\d+入账工资，人民币\\d+\\.\\d+。.*", "入账","通知"));
        rules.add(new Rule(1, "【.*?】您尾号(为)*.*?的.*?信用卡(，于)*.*?发生退款，金额.*", "退款","通知"));
        rules.add(new Rule(1, "【.*】您账户\\d+于\\d+.*?交易.*", "交易","通知"));
        rules.add(new Rule(1, "^(.*?公安局|交管部门|.*防汛指挥部).*(提醒|提示|感谢).*", "提醒","提醒"));
        rules.add(new Rule(1, "【账单提醒】尊敬的\\d+用户，您\\d+年\\d+月份账单合计.*?元.*", "账单提醒","账单"));
        rules.add(new Rule(1, ".*(文旅|文物旅游局|旅游局).*", "文旅欢迎","提醒"));
        rules.add(new Rule(1, ".*(满\\d+\\.\\d+元可用|\\d+减\\d).*", "营销短信","广告"));
        rules.add(new Rule(1, ".*，您个人信用卡账户临额调整成功，额度临时变更为\\d+元，有效期.*?，当前可用额度.*?元.*", "临时额度变更提醒","通知"));
        rules.add(new Rule(1, "【京东】您通过.*?支付.*?元。.*", "支付提醒","通知"));
        rules.add(new Rule(1,
            ".*(\\d+元买菜金|赚积分|立减|加赠|直降|低至|可减|福利|省\\d+元|红包到账|会员日|红包(已)*到账|买.赠.|大额券|\\d+-\\d+.*券|0元|免费领|\\d+.*?元.*红包|￥\\d+(专属)*加价券).*",
            "广告","广告"));
        rules.add(new Rule(1, ".*自动充值.*", "自动充值","通知"));
        rules.add(new Rule(1, ".*仅(需)* *(￥) *\\d+(\\.\\d+)*+(元)*.*", "广告","广告"));
        rules.add(new Rule(1, "【联通沃邮箱】尊敬的客户，中国联通邀您查看\\d+月通信账单，请点击.*", "账单","账单"));
        rules.add(new Rule(1, "【高德地图】您于.*?出发的行程，.*您的订单已被取消，建议您尽快重新下单。", "订单取消","提醒"));
        rules.add(new Rule(1, ".*领取.*?券.*", "广告","广告"));
        rules.add(new Rule(1, "【高德地图】您于.*申请的发票已开具完成，可前往接收邮箱或高德地图APP内查看", "发票开具","提醒"));
        rules.add(new Rule(1, "【阿里云】 【工单提醒】.*", "工单提醒","提醒"));
        rules.add(new Rule(1, "(【闲鱼】)*.*已为你降价成功，去.*看看，回TD退订(【闲鱼】)*", "降价","通知"));
        rules.add(new Rule(1, "【美团】您在.*?订的外卖订单已经为您取消。给您带来的不便，敬请谅解。欢迎您选择其他商家继续下单。", "订单取消通知","通知"));
        rules.add(new Rule(1, "【积分到账提醒】尊敬的客户，.*?，您的手机\\(\\d{11}\\)账户新增\\d+积分.*?【中国移动】", "积分到账","通知"));
        rules.add(new Rule(1, "\\[国网北京电力(公司)*\\]尊敬的客户（户号：.*?，地址：.*?）您好，.*", "电费","提醒"));
        rules.add(new Rule(1, "(【Microsoft】)*Microsoft: .*? 有异常登录。请通过 .*", "异常登录","提醒"));
        rules.add(new Rule(1, ".*快递.*(放|到达|代收|都在).*", "快递取件","快递"));
        rules.add(new Rule(1, "【招商银行】您尾号\\d+的账户于.*?，交易金额：.*?。", "交易","通知"));
        rules.add(new Rule(1, "【京东小金库】尊敬的用户，您通.*?小金库商城消费.*元.*", "交易","通知"));
        rules.add(new Rule(1, "【京东金融】您于.*?提现申请成功.*", "提现成功","通知"));
        rules.add(new Rule(1, "【京东金融】您已于.*成功充值.*元。", "充值","提醒"));
        rules.add(new Rule(1, "【.*?】您尾号为\\d+.*?卡于.*?收入0.01元.*。", "银行卡入账","通知"));
        rules.add(new Rule(1, "【.*?】尊敬的旅客，您购买的.*航班已开放.*?，戳.*?办理。", "航班","提醒"));
        rules.add(new Rule(1, "【.*?】您已为.*?旅客购买.*?预计起飞时间.*?，预计到达时间.*", "航班","通知"));
        rules.add(new Rule(1, "【.*?】客官，您购买的.*?已投保成功，被保人.*?查看详情", "投保成功","通知"));
        rules.add(new Rule(1, "【.*?】您订的.*，.*航班已出票.*", "航班出票","提醒"));
        rules.add(new Rule(1, "【.*?】航班取消提醒：尊敬的旅客，很抱歉通知您：.*?已取消.*", "航班取消","提醒"));
        rules.add(new Rule(1, "【.*?】您本次骑行未在P点还车.*?", "未规范停车提醒","提醒"));
        rules.add(new Rule(1, "【.*?】您好，您在.*?预约的.*?从.*?到.*?的出行服务，将由.*?提供。司机.*?将准时来接您.*", "打车预约","通知"));
        rules.add(new Rule(1, "沃助理温馨提醒：您漏接了.*?于.*?的来电。.*", "漏话提醒","提醒"));
        rules.add(new Rule(1, "联通秘书温馨提醒：您的电话*?有.*?的漏接电话.*", "漏话提醒","提醒"));
        rules.add(new Rule(1, "【.*】货号.*?来.*?取.*?", "快递取件提醒","快递"));
        rules.add(new Rule(1, "【.*】订单.*，.*您已购.*?次.*?,.*?开。", "购票成功","通知"));
        
        
    }
    
    public static Rule tag(String text) {
        for (Rule rule : rules) {
            if (text.matches(rule.regex)) {
                return rule;
            }
        }
        return new Rule(0,"", "none","其他") ;
    }
    

    @Data
    public static class Rule {
        
        private Integer weight;
        private String regex;
        private String tag;
        private String category;
        
        public Rule(Integer weight, String regex, String tag, String category) {
            this.weight = weight;
            this.regex = regex;
            this.tag = tag;
            this.category = category;
        }
        
    }
    
}


